const Service = require('egg').Service;

const { Result } = require('../utils/Result');

class User extends Service {

  async getAll(pageNo, pageSize, orderBy = 'id', order = 'ASC') {

    const offset = pageSize * (pageNo - 1);

    const { count, rows } = await this.ctx.models.user.findAndCountAll({
      // attributes: [ 'id', 'name', 'config' ],
      // where: {
      //   deleted: 0,
      // },
      order: [[ orderBy, order ]],
      limit: parseInt(pageSize, 10),
      offset,
    });

    return Result.success(rows)
      .setTotal(count);
  }

  async insertUser(user) {
    const res = await this.ctx.models.user.create(user);
    console.log(res);
    return Result.success();
  }
}
module.exports = User;
